{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          视频媒体    社交媒体    传统媒体    朋友推荐   浏览器搜索    新闻推送\n",
      "18岁以下   66.70%  20.00%   6.70%  13.30%  33.30%   6.70%\n",
      "18-30岁  61.00%  52.00%   8.70%  21.00%  26.00%  33.00%\n",
      "30-50岁  52.00%  43.50%  16.30%  20.70%  16.30%  28.30%\n",
      "50岁以上   43.50%  26.10%  26.10%  30.40%  17.40%  34.80%\n",
      "[8, 2, 1, 2, 4, 1]\n",
      "[57, 48, 8, 20, 24, 31]\n",
      "[42, 35, 13, 17, 13, 23]\n",
      "[9, 5, 5, 6, 3, 7]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\28651\\AppData\\Local\\Temp\\ipykernel_35768\\3365743601.py:10: FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.\n",
      "  df = df.applymap(lambda x: format(x, '.2%'))\n"
     ]
    }
   ],
   "source": [
    "G1_18 = [0.667, 0.2, 0.067, 0.133, 0.333, 0.067]\n",
    "G2_30 = [0.61, 0.52, 0.087, 0.21, 0.26, 0.33]\n",
    "G3_50 = [0.52, 0.435, 0.163, 0.207, 0.163, 0.283]\n",
    "G4_100 = [0.435, 0.261, 0.261, 0.304, 0.174, 0.348]\n",
    "\n",
    "#将这些百分比保存为Excel\n",
    "import pandas as pd\n",
    "df = pd.DataFrame([G1_18, G2_30, G3_50, G4_100], columns=['视频媒体', '社交媒体', '传统媒体', '朋友推荐', '浏览器搜索', '新闻推送'], index=['18岁以下', '18-30岁', '30-50岁', '50岁以上'])\n",
    "#转换为百分比\n",
    "df = df.applymap(lambda x: format(x, '.2%'))\n",
    "print(df)\n",
    "df.to_excel('了解渠道占比表.xlsx')\n",
    "\n",
    "\n",
    "G1_count = 12.0\n",
    "G2_count = 93.0\n",
    "G3_count = 80.0\n",
    "G4_count = 20.0\n",
    "\n",
    "#四舍五入取整\n",
    "G1 = [round(G1_18[i]*G1_count) for i in range(6)]\n",
    "G2 = [round(G2_30[i]*G2_count) for i in range(6)]\n",
    "G3 = [round(G3_50[i]*G3_count) for i in range(6)]\n",
    "G4 = [round(G4_100[i]*G4_count) for i in range(6)]\n",
    "print(G1)\n",
    "print(G2)\n",
    "print(G3)   \n",
    "print(G4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
